﻿<?php

class Application_Model_Registration extends Zend_Db_Table_Abstract
{
    protected $_name = 'users';
    
    //Добавление пользователя в базу данных
    public function registration($data) {
        return $this->insert($data);
    }
    
   //Отправка уведомления о регистрации
    public function sendEmail($email, $password, $firstName) {
        //тело письма и ссылка на профиль
        $text = $this->translate('Dear '.$firstName.', welcome to Logisticway.
        This is a confirmation email that you have registered with Logisticway. Your new account has been setup and you can now login to our client area using the details below:
        Your login is your email address: '.$email.'
        Your password: '.$password.'
        To login, visit http://logisticway.com/auth/login 
        ----
        Kind regards,
        Logisticway Accounting
        Logisticway LLP.
        www.logisticway.com ');
        $transport = new Zend_Mail_Transport_Sendmail();
        $mail = new Zend_Mail();
        $mail->addTo($email)
            ->setSubject('Registration')
            ->setBodyText($text)
            ->setFrom('admin@logisticway.com');

        try {
            $mail->send($transport);
            echo "Send!<br />\n";
        } catch (Exception $ex) {
            echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
        }
    }
    
    public function setRole($data) {
        $this->_name = 'role_users';
        $this->insert($data);
    }
    
    public function getAllCountries() {
        $this->_name = 'countries';
        $select = $this->select()->from($this->_name);//, array('name'));
        return $this->fetchAll($select)->toArray();
    }
}
